package com.game.model;

import java.util.ArrayList;

public class FactoryPai {

	public static FactoryPai instance = null;

	public ArrayList<Pai> paiList = new ArrayList<>();

	public static FactoryPai getInstance() {
		if (instance == null) {
			instance = new FactoryPai();
		}
		return instance;
	}

	public FactoryPai() {
		initPai();
	}

	public void initPai() {

		Pai pai1 = new Pai(0, "铲子", 0, 0.2, 0.4, 1.2,3.6,18,90);
		paiList.add(pai1);
		Pai pai2 = new Pai(1, "砍刀", 0, 0.3, 0.6, 1.8,5.4,27,135);
		paiList.add(pai2);
		Pai pai3 = new Pai(2, "锄头", 0, 0.4, 0.8, 2.4,7.2,34.75,180);
		paiList.add(pai3);
		Pai pai4 = new Pai(3, "人参", 0, 0.4, 0.8, 2.4,7.2,34.75,180);
		paiList.add(pai4);
		Pai pai5 = new Pai(4, "灵芝", 0.5, 1, 2, 6,18,90,450);
		paiList.add(pai5);
		Pai pai6 = new Pai(5, "雪莲", 0.5, 1, 2, 6,18,90,450);
		paiList.add(pai6);
		Pai pai6T = new Pai(6, "铜丹炉", 0.6, 1.2, 2.4, 7.2,21.6,108,415);
		paiList.add(pai6T);
		Pai pai7 = new Pai(7, "黄丹炉", 0.7, 1.4, 2.8, 8.4,25.2,126,630);
		paiList.add(pai7);
		Pai pai8 = new Pai(8, "绿丹炉", 0.8, 1.6, 3.2, 9.6,28.8,144,720);
		paiList.add(pai8);
		Pai pai9 = new Pai(9, "WILD2x", 0, 0, 0, 0,0,0,0);
		paiList.add(pai9);
		Pai pai10 = new Pai(10, "WILD3x", 0, 0, 0, 0,0,0,0);
		paiList.add(pai10);
		Pai pai11 = new Pai(11, "WILD5x", 0, 0, 0, 0,0,0,0);
		paiList.add(pai11);
		Pai pai12 = new Pai(12, "SCATTER", 0, 0, 0, 0,0,0,0);
		paiList.add(pai12);
		/*
		Pai pai1 = new Pai(0, "A", 0, 7, 15, 40);
		paiList.add(pai1);
		Pai pai2 = new Pai(1, "K", 0, 7, 15, 40);
		paiList.add(pai2);
		Pai pai3 = new Pai(2, "O", 0, 5, 10, 25);
		paiList.add(pai3);
		Pai pai4 = new Pai(3, "J", 0, 5, 10, 25);
		paiList.add(pai4);
		Pai pai5 = new Pai(4, "钥匙", 0, 10, 15, 50);
		paiList.add(pai5);
		Pai pai6 = new Pai(5, "罐子", 0, 15, 25, 75);
		paiList.add(pai6);
		Pai pai6T = new Pai(6, "金字塔", 0, 15, 40, 100);
		paiList.add(pai6T);
		Pai pai7 = new Pai(7, "法老", 3, 25, 100, 200);
		paiList.add(pai7);
		Pai pai8 = new Pai(8, "狗头", 5, 40, 150, 300);
		paiList.add(pai8);
		Pai pai9 = new Pai(9, "艳后", 10, 50, 200, 500);
		paiList.add(pai9);
		Pai pai10 = new Pai(10, "黑猫(BOUNS)", 0, 0, 0, 0);
		paiList.add(pai10);
		Pai pai11 = new Pai(11, "木乃伊(WILD)", 0, 0, 0, 0);
		paiList.add(pai11);
		Pai pai12 = new Pai(12, "眼睛(SCATTER)", 0, 0, 0, 0);
		paiList.add(pai12);
	*/}

	public Pai getOneCharacterByRandomValue(float randomValue, String duiBiValue, int totalRate, boolean isHaveFree) {
		String arr[] = duiBiValue.split(",");
		float count = 0;
		for (int i = 0; i < arr.length; i++) {
			
			float gai1 = count / totalRate;
			float gai2 = (count + Float.valueOf(arr[i]).floatValue()) / totalRate;
			// System.out.println("概率:"+gai1+"|"+gai2);
			if (randomValue >= gai1 && (randomValue < gai2)) {
				return getOnePaiByType(i, isHaveFree);
			}
			count += Float.valueOf(arr[i]).floatValue();
		}
		System.out.println("null啦");
		return null;
	}

	public Pai getOnePaiByType(int type, boolean isHaveFree) {
		double randomNumber;  
		randomNumber = Math.random();
		if (!isHaveFree) {
			if ((type == 9 || type == 10 || type == 11 || type == 12) && randomNumber >= 0.70 && randomNumber <= 0.85) {
				return paiList.get(type);
			} else {
				return paiList.get((int) (Math.random() * 9));
			}
		} else {
			return paiList.get(type);
		}
	}

}
